package cn.iocoder.yudao.module.book.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.book.controller.app.vo.AppBookRecordInfoVO;
import cn.iocoder.yudao.module.book.controller.app.vo.AppBookRecordReqVO;
import cn.iocoder.yudao.module.book.controller.app.vo.AppBookShelfRespVO;
import cn.iocoder.yudao.module.book.service.app.AppBookRecordService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bookRecord")
public class AppBookRecordController {

    @Resource
    private AppBookRecordService bookRecordService;

    @GetMapping("/getBookRecordList")
    @Operation(summary = "查询阅读记录")
    public CommonResult<AppBookRecordInfoVO> getBookRecordList() {
        return CommonResult.success(bookRecordService.getBookRecordList());
    }

    @PostMapping("/createBookRecord")
    @Operation(summary = "添加阅读记录")
    public CommonResult<Long> createBookRecord(@Valid @RequestBody AppBookRecordReqVO bookRecordReqVO) {
        return CommonResult.success(bookRecordService.createBookRecord(bookRecordReqVO));
    }

    @DeleteMapping("/deleteBookRecord/{id}")
    @Operation(summary = "删除阅读记录")
    public CommonResult<Boolean> deleteBookRecord(@PathVariable Long id) {
        bookRecordService.deleteBookRecord(id);
        return CommonResult.success(true);
    }

    @DeleteMapping("/deleteAllBookRecord")
    @Operation(summary = "删除所有阅读记录")
    public CommonResult<Boolean> deleteAllBookRecord() {
        bookRecordService.deleteAllBookRecord();
        return CommonResult.success(true);
    }


    @GetMapping("/queryMyRecentlyReadBooks/{type}")
    @Operation(summary = "查询我的最近阅读的图书")
    public CommonResult<List<AppBookShelfRespVO>> queryMyRecentlyReadBooks(@PathVariable String type) {
        List<AppBookShelfRespVO> vo = bookRecordService.queryMyRecentlyReadBooks(type);
        return CommonResult.success(vo);
    }


    @GetMapping("/clearBookReadingHistory")
    @Operation(summary = "清空阅读记录")
    public CommonResult<Integer> clearBookReadingHistory() {
        return CommonResult.success(bookRecordService.clearBookReadingHistory());
    }
}